package io.gitee.tianhaoran.chat.sdk.api.interceptor;

import io.gitee.tianhaoran.chat.sdk.api.def.Const;
import lombok.NonNull;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

import java.io.IOException;

/**
 * 默认请求头处理拦截器
 * <p>
 * 作者：沈自在
 **/
public class HeaderMaskInterceptor implements Interceptor {
    @Override
    public @NonNull Response intercept(@NonNull Chain chain) throws IOException {
        // 1. 获取原始 Request
        Request original = chain.request();

        // 2. 构建请求
        Request request = original.newBuilder()
                .url(original.url())
                .header("Content-Type", Const.JSON_CONTENT_TYPE)
                .header("User-Agent", Const.DEFAULT_USER_AGENT)
                .header("Accept", Const.SSE_CONTENT_TYPE)
                .method(original.method(), original.body())
                .build();

        // 3. 返回执行结果
        return chain.proceed(request);
    }
}
